Skip to content

8374804: ConditionalFeature media queries#2161

Closed
mstr2 wants to merge 4 commits into
openjdk:masterfrom
mstr2:feature/conditional-feature-query
Closed

8374804: ConditionalFeature media queries#2161
mstr2 wants to merge 4 commits into
openjdk:masterfrom
mstr2:feature/conditional-feature-query

Conversation

@mstr2

@mstr2 mstr2 commented May 3, 2026

Copy link
Copy Markdown
Collaborator

This PR adds the -fx-supports-conditional-feature media query, which allows applications to adapt their stylesheets to different platforms with varying conditional feature support. Currently, the built-in themes use hard-coded logic to include or exclude conditional-feature stylesheets. The new media query allows us to potentially remove the hard-coded logic in the future, and gives third-party themes an API to query conditional feature support.



Progress

  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8384139 to be approved
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issues

  • JDK-8374804: ConditionalFeature media queries (Enhancement - P4)
  • JDK-8384139: ConditionalFeature media queries (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/2161/head:pull/2161
$ git checkout pull/2161

Update a local copy of the PR:
$ git checkout pull/2161
$ git pull https://git.openjdk.org/jfx.git pull/2161/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2161

View PR using the GUI difftool:
$ git pr show -t 2161

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/2161.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented May 3, 2026

Copy link
Copy Markdown

👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

@mstr2 This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8374804: ConditionalFeature media queries

Reviewed-by: angorya, mhanl

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 1 new commit pushed to the master branch:

  • b932758: 8386698: PlatformUtil has unused fields and methods

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot added the rfr Ready for review label May 3, 2026
@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: rfr. This can be overridden with the /reviewers command.

@mstr2

mstr2 commented May 3, 2026

Copy link
Copy Markdown
Collaborator Author

/reviewers 2

@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

@mstr2
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@mlbridge

mlbridge Bot commented May 3, 2026

Copy link
Copy Markdown

Webrevs

@mstr2

mstr2 commented May 3, 2026

Copy link
Copy Markdown
Collaborator Author

/csr

@openjdk openjdk Bot added the csr Need approved CSR to integrate pull request label May 3, 2026
@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

@mstr2 has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@mstr2 please create a CSR request for issue JDK-8374804 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@kevinrushforth

Copy link
Copy Markdown
Member

This looks like a nice addition. I'll review the CSR, but I hope others will review the code.

Reviewers: @andy-goryachev-oracle , ???

@andy-goryachev-oracle

Copy link
Copy Markdown
Contributor

yes, it's in my review queue

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing looks good. My feedback is mostly about documentation - I know it is very difficult to write docs from a new user perspective, especially since you know how the internals work in great detail.

</tr>
<tr>
<td class="value">-fx-prefers-persistent-scrollbars</td>
<td class="value nowrap">-fx-prefers-persistent-scrollbars</td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed this: why the -fx prefix is here but not in all the others?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CSS, this is called a vendor prefix. It is used for all symbols that have not yet achieved what amounts to universal concensus. JavaFX uses vendor prefixes quite extensively; in fact, almost all styleable properties are vendor-prefixed (though not all: visibility and transition are standard-compliant and don't use a vendor prefix).

Most of the media features we support are standard-compliant, and you'll find that they also work exactly the same in other CSS applications like web browsers. However, -fx-prefers-persistent-scrollbars is not a standard feature; neither is -fx-supports-conditional-feature.

</tr>
<tr>
<td class="value nowrap">-fx-supports-conditional-feature</td>
<td class="value">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cell looks way too busy. do you think it might be worth either extracting it into a dedicated table where each feature can be explained/described?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried arranging the constants in several different ways, including a table-like vertical listing. However, that introduces huge amounts of whitespace that doesn't help readability either. I'm not too excited about adding descriptions to all of the constants; that information is only a click away now that we're linking to the Platform.isSupported(ConditionalFeature) method. I'd like to avoid duplicating normative specification (the CSS reference is a normative specification, not merely an informational document).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, especially since you've added the link.

<span class="nowrap">input-touch</span> | <span class="nowrap">input-multitouch</span> |
<span class="nowrap">input-pointer</span></td>
<td>discrete</td>
<td>Evaluates to <code>true</code> if <code>Platform.isSupported(ConditionalFeature)</code> returns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better if this were a link to Platform.isSupported(ConditionalFeature) ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I've added the link.

}
""";

Stylesheet stylesheet = new CssParserShim().parseUnmerged(stylesheetText, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case of invalid conditional feature like

@media (-fx-supports-conditional-feature: xxx)
{
    .button { -fx-background-color: red; }
}

the CssParser writes to stderr - is that expected?
if so, should it be tested?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think that CssParser is one of the... let's call it least well-developed parts of JavaFX. Errors from MediaQueryParser are fed back into CssParser, where they are treated like all other errors. So that's not "new" code at work here.

Should the way CssParser reports errors be tested? Maybe, but then again, that time is better spent just discarding it entirely and replacing it with an implementation that's not as bad. In any case, it's out of scope for this PR because the changes here don't touch error reporting at all.

<td>discrete</td>
<td>Evaluates to <code>true</code> if <code>Platform.isSupported(ConditionalFeature)</code> returns
<code>true</code> for the specified conditional feature.<br>This media feature cannot be
evaluated in a boolean context.</td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain in more easily understandable terms that the "boolean context" means? Assume the reader is trying to use it for the first time.

Especially confusing because isSupported is a boolean...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a link to the paragraph "Evaluating Media Features in a Boolean Context" which appears a bit earlier in the document.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, thanks!

@mstr2

mstr2 commented May 25, 2026

Copy link
Copy Markdown
Collaborator Author

@Maran23 Do you want to to be the second reviewer?

@Maran23

Maran23 commented May 25, 2026

Copy link
Copy Markdown
Member

@Maran23 Do you want to to be the second reviewer?

Yes! Will review and test in the coming days.

@Maran23 Maran23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Changes look fine and work as expected.
Have 2 very minor suggestions.

</figure>
<h5>Evaluating Media Features in a Boolean Context</h5>
<h5 id="mf-boolean-context">Evaluating Media Features in a Boolean Context</h5>
<p>If the colon and value is omitted, the media feature is evaluated in a boolean context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already existing, but this should probably be:

Suggested change
<p>If the colon and value is omitted, the media feature is evaluated in a boolean context.
<p>If the colon and value are omitted, the media feature is evaluated in a boolean context.

We can also do that in a follow up, but IMO is close enough so fine for me to do here.

assertEquals(3, mediaRule.getQueries().size());

var expected = FunctionExpression.of("-fx-supports-conditional-feature", "scene3d", _ -> null, true);
var actual = mediaRule.getQueries().get(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor: This can be getFirst() (and .get(2) could be getLast() below)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually only do this if I specifically only need the first (or last) element, but not when the code pattern repeats for subsequent elements (0, 1, 2 in this case).

@kevinrushforth

Copy link
Copy Markdown
Member

This looks like a nice addition. I'll review the CSR, but I hope others will review the code.

I've reviewed the CSR. It is ready to be Finalized.

@openjdk openjdk Bot added ready Ready to be integrated and removed csr Need approved CSR to integrate pull request labels Jun 19, 2026
@mstr2

mstr2 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

/integrate

@openjdk

openjdk Bot commented Jun 19, 2026

Copy link
Copy Markdown

Going to push as commit 8020a85.
Since your change was applied there has been 1 commit pushed to the master branch:

  • b932758: 8386698: PlatformUtil has unused fields and methods

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Jun 19, 2026
@openjdk openjdk Bot closed this Jun 19, 2026
@openjdk openjdk Bot removed ready Ready to be integrated rfr Ready for review labels Jun 19, 2026
@openjdk

openjdk Bot commented Jun 19, 2026

Copy link
Copy Markdown

@mstr2 Pushed as commit 8020a85.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@Maran23 Maran23 mentioned this pull request Jun 22, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants